package com.hl.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.domain.Consultwait;
import com.hl.domain.Free;
import com.hl.mapper.ConsultwaitMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class ConsultwaitService {

    @Autowired
    private ConsultwaitMapper consultwaitMapper;

    /**
     * 查询所有咨询预约信息
     * @param page
     * @param size
     * @return
     */
    public HashMap<String, Object> selectAllConsultWait(int page, int size){
        //设置分页
        PageHelper.startPage(page, size);
        //查询全部数据
        List<Consultwait> list = consultwaitMapper.selectAllConsultWait();
        PageInfo<Consultwait> pageInfo = new PageInfo<Consultwait>(list);
        //获取总数
        int total = (int) pageInfo.getTotal();
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("list", list);
        map.put("total", total);
        return map;
    }

    /**
     * 分页条件查询
     * @param info
     * @param startDate
     * @param endDate
     * @param page
     * @param size
     * @return
     */
    public HashMap<String,Object> selectConsultByCondition(String info, Date startDate, Date endDate, int page, int size){
        //设置分页
        PageHelper.startPage(page, size);
        //查询全部数据
        List<Consultwait> list = consultwaitMapper.selectConsultWaitByCondition(info,startDate,endDate);
        PageInfo<Consultwait> pageInfo = new PageInfo<Consultwait>(list);
        //获取总数
        int total = (int) pageInfo.getTotal();
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("list", list);
        map.put("total", total);
        return map;
    }

    /**
     * 删除预约信息
     * @param id
     * @return
     */
    public int deleteConsultWaitById(int id){
        return consultwaitMapper.deleteConsultWaitById(id);
    }

    /**
     * 根据预约id修改预约信息
     * @param consultwait
     * @return
     */
    public int updateConsultWait(Consultwait consultwait){
        return consultwaitMapper.updateConsultWait(consultwait);
    }


    //查询状态信息
    public List<Integer> selectStatus(){
        return consultwaitMapper.selectStatus();
    }

 	//用户发出预约，将预约信息插入表中
    public int addConsult(Consultwait consultwait){
        return consultwaitMapper.insert(consultwait);
    }

}
